package com.xwaf.platform.web.excel;

import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;

import com.xwaf.platform.common.excel.easy.excel.config.ExcelDefinition;
import com.xwaf.platform.common.excel.easy.excel.parsing.ExcelHeader;

/**
 * 
 * <p>
 * 营收日报表头
 * <p>
 * 
 * @author 李聪 <br>
 * @email xwaf_love@yeah.net <br>
 * @since JDK 1.8<br>
 * @date 2019年12月30日 上午9:34:57 <br>
 * @see 无<br>
 *      Copyright (c) 2019, xwaf_love@yeah.net All Rights Reserved.<br>
 */
public class RevenueCustHeader implements ExcelHeader {

	@Override
	public void buildHeader(Sheet sheet, ExcelDefinition excelDefinition, List<?> beans) {
		Workbook workbook = sheet.getWorkbook();
		CellStyle style = workbook.createCellStyle();
		style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 居中
		style.setWrapText(true);// 设置自动换行
		/*
		 * Font font = workbook.createFont(); font.setFontName("仿宋_GB2312");
		 * //font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//粗体显示
		 * font.setFontHeightInPoints((short) 12);
		 * style.setFont(font);//选择需要用到的字体格式
		 */
		// 单元格范围 参数（int firstRow, int lastRow, int firstCol, int lastCol)
		CellRangeAddress nameMerge = new CellRangeAddress(0, 1, 0, 0);
		sheet.addMergedRegion(nameMerge); // 姓名
		CellRangeAddress employeeIdMerge = new CellRangeAddress(0, 1, 1, 1);
		sheet.addMergedRegion(employeeIdMerge); // 工号
		CellRangeAddress stationMerge = new CellRangeAddress(0, 1, 2, 2);
		sheet.addMergedRegion(stationMerge); // 售票点
		CellRangeAddress salePointMerge = new CellRangeAddress(0, 1, 3, 3);
		sheet.addMergedRegion(salePointMerge); // 线路
		CellRangeAddress typeMerge = new CellRangeAddress(0, 1, 4, 4);
		sheet.addMergedRegion(typeMerge); // 类型
		CellRangeAddress saleMerge = new CellRangeAddress(0, 0, 5, 7);
		sheet.addMergedRegion(saleMerge); // 售票
		CellRangeAddress badMerge = new CellRangeAddress(0, 0, 8, 10);
		sheet.addMergedRegion(badMerge); // 废票
		CellRangeAddress refundMerge = new CellRangeAddress(0, 0, 11, 14);
		sheet.addMergedRegion(refundMerge); // 退票
		CellRangeAddress insuranceMerge = new CellRangeAddress(0, 0, 15, 16);
		sheet.addMergedRegion(insuranceMerge); // 售保
		CellRangeAddress refundInsuranceMerge = new CellRangeAddress(0, 0, 17, 18);
		sheet.addMergedRegion(refundInsuranceMerge); // 退保
		CellRangeAddress badInsuranceMerge = new CellRangeAddress(0, 0, 19, 20);
		sheet.addMergedRegion(badInsuranceMerge); // 废保
		CellRangeAddress totalMerge = new CellRangeAddress(0, 0, 21, 23);
		sheet.addMergedRegion(totalMerge); // 金额

		// 生成第一行
		Row row = sheet.createRow(0);
		Cell nameCell = row.createCell(0);
		nameCell.setCellStyle(style);
		nameCell.setCellValue("姓名");
		Cell employeeIdCell = row.createCell(1);
		employeeIdCell.setCellStyle(style);
		employeeIdCell.setCellValue("工号");
		Cell stationCell = row.createCell(2);
		stationCell.setCellStyle(style);
		stationCell.setCellValue("售票点");
		Cell salePointCell = row.createCell(3);
		salePointCell.setCellStyle(style);
		salePointCell.setCellValue("线路");
		Cell typeMergeCell = row.createCell(4);
		typeMergeCell.setCellStyle(style);
		typeMergeCell.setCellValue("类型");
		Cell saleMergeCell = row.createCell(5);
		saleMergeCell.setCellStyle(style);
		saleMergeCell.setCellValue("售票");
		Cell badMergeCell = row.createCell(8);
		badMergeCell.setCellStyle(style);
		badMergeCell.setCellValue("废票");
		Cell refundMergeCell = row.createCell(11);
		refundMergeCell.setCellStyle(style);
		refundMergeCell.setCellValue("退票");
		Cell insuranceMergeCell = row.createCell(15);
		insuranceMergeCell.setCellStyle(style);
		insuranceMergeCell.setCellValue("售保");
		Cell refundInsuranceMergeCell = row.createCell(17);
		refundInsuranceMergeCell.setCellStyle(style);
		refundInsuranceMergeCell.setCellValue("退保");
		Cell badInsuranceMergeCell = row.createCell(19);
		badInsuranceMergeCell.setCellStyle(style);
		badInsuranceMergeCell.setCellValue("废保");
		Cell totalMergeCell = row.createCell(21);
		totalMergeCell.setCellStyle(style);
		totalMergeCell.setCellValue("金额");

		// 生成第二行
		Row row2 = sheet.createRow(1);
		Cell saleTicketCell = row2.createCell(5);
		saleTicketCell.setCellStyle(style);
		saleTicketCell.setCellValue("票数");
		Cell saleFeeCell = row2.createCell(6);
		saleFeeCell.setCellStyle(style);
		saleFeeCell.setCellValue("金额");
		Cell saleFuelCell = row2.createCell(7);
		saleFuelCell.setCellStyle(style);
		saleFuelCell.setCellValue("燃油费");
		Cell badCell = row2.createCell(8);
		badCell.setCellStyle(style);
		badCell.setCellValue("张数");// 废票
		Cell badFeeCell = row2.createCell(9);
		badFeeCell.setCellStyle(style);
		badFeeCell.setCellValue("金额");
		Cell badFuelCell = row2.createCell(10);
		badFuelCell.setCellStyle(style);
		badFuelCell.setCellValue("燃油费");
		Cell refundCell = row2.createCell(11);
		refundCell.setCellStyle(style);
		refundCell.setCellValue("张数"); // 退票
		Cell refundFeeCell = row2.createCell(12);
		refundFeeCell.setCellStyle(style);
		refundFeeCell.setCellValue("金额");
		Cell refundFuelCell = row2.createCell(13);
		refundFuelCell.setCellStyle(style);
		refundFuelCell.setCellValue("燃油费");
		Cell refundChargeCell = row2.createCell(14);
		refundChargeCell.setCellStyle(style);
		refundChargeCell.setCellValue("手续费");
		Cell insuranceNumCell = row2.createCell(15); // 售保
		insuranceNumCell.setCellStyle(style);
		insuranceNumCell.setCellValue("张数");
		Cell insuranceFeeCell = row2.createCell(16);
		insuranceFeeCell.setCellStyle(style);
		insuranceFeeCell.setCellValue("金额");
		Cell refundInsuranceNumCell = row2.createCell(17); // 退保
		refundInsuranceNumCell.setCellStyle(style);
		refundInsuranceNumCell.setCellValue("张数");
		Cell refundInsuranceFeeCell = row2.createCell(18);
		refundInsuranceFeeCell.setCellStyle(style);
		refundInsuranceFeeCell.setCellValue("金额");
		Cell badInsuranceNumCell = row2.createCell(19); // 废保
		badInsuranceNumCell.setCellStyle(style);
		badInsuranceNumCell.setCellValue("张数");
		Cell badInsuranceFeeCell = row2.createCell(20);
		badInsuranceFeeCell.setCellStyle(style);
		badInsuranceFeeCell.setCellValue("金额");
		Cell ticketSumCell = row2.createCell(21); // 金额
		ticketSumCell.setCellStyle(style);
		ticketSumCell.setCellValue("客票");
		Cell insuranceSumCell = row2.createCell(22);
		insuranceSumCell.setCellStyle(style);
		insuranceSumCell.setCellValue("保费");
		Cell totalCell = row2.createCell(23);
		totalCell.setCellStyle(style);
		totalCell.setCellValue("合计");
	}
}
